/*************************************************************************
	> File Name: calendar.cc
	> Author: life
	> Created Time: Sat 10 Oct 2020 06:56:06 PM CST
 ************************************************************************/

#include <iostream>
#include <string>

using namespace std;

int main(int argc,char ** argv)
{
	if(argc != 3)
	{
		printf("./calendar year mouth\n");
		return -1;
	}

	int year,mouth,week,day = 1,mouth_day;
	long int days;
	int year_day[13] = {0,31,59,90,120,151,181,212,243,273,304,334,365};

	year = stoi(argv[1]) - 1900;
	mouth = stoi(argv[2]) ;

	if(mouth < 1 || mouth > 12 )
	{
		cout << "the mouth input error" << endl ;
		return -1;
	}

	days = year * 365 + ((year - 1) / 4) + year_day[mouth - 1];

	if(year % 4 == 0 && mouth > 2 )
		days = days + 1;

	mouth_day = year_day[mouth] - year_day[mouth - 1];
	if(year % 4 == 0 && mouth == 2)
		mouth_day += 1;

	week = days % 7 + 1;
	cout << week << "  "<< mouth_day << "  "<< endl ;
	cout << "******************************************************" << endl;
	cout << "一\t二\t三\t四\t五\t六\t日" << endl ;
	int i = 0;
	while ( i < week + mouth_day)
	{
		if (i >  week - 1)
			cout << day++;
		cout << "\t";
		if( i % 7 == 0 )
			cout << endl ;
		i += 1;
	}
	cout << endl ;
	cout << "******************************************************" << endl;
	return 0;
}
